﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Infrastructure.Interfaces;
using Traceability_Management.Read.Api.Application.Command.RabitsWay;

namespace Traceability_Management.Read.Api.Application.CommandHandler.RabitsWay
{
    public class ShowShopCommandHandler : IRequestHandler<ShowShopCommand, ApiResult<List<Shop_Table>>>
    {
        IBaseReponsitory<Shop_Table> Shops;

        public ShowShopCommandHandler(IBaseReponsitory<Shop_Table> Shops)
        {
            this.Shops = Shops;
        }

        public async Task<ApiResult<List<Shop_Table>>> Handle(ShowShopCommand request, CancellationToken cancellationToken)
        {
            var list = Shops.GetQuery();
            return new ApiResult<List<Shop_Table>> 
            {
            Code=ApiEnum.Success,
            Message="查询成功了",
            Data=await list.ToListAsync()
            };
        }
    }
}
